//
//  GiftDetailViewController.m
//  GameBaby
//
//  Created by keyZhang on 14-1-11.
//  Copyright (c) 2014年 keyZhang. All rights reserved.
//

#import "GiftDetailViewController.h"
#import "DataService.h"
#import "GiftButton.h"

#define RELEASE_OBJECT(obj)  if(obj != nil) { obj = nil; }

#define SINASHEET_TAG 1000
#define TCSHEET_TAG 1001
#define SHARE_CONTENT @"独家礼包，瞬间就变高富帅白富美，我再也不用担心我的装备了，真是各种给力，快来领取吧！E蜗卡AppStore下载地址：https://itunes.apple.com/cn/app/e-wo-ka/id841721856?mt=8"

#define SHARE_URL @"http://www.ewoka.com"

@interface GiftDetailViewController ()
{
    UIScrollView *scrView;
    UIImageView *headImg;
    UILabel *gNameLabel;
    UILabel *gTypeLabel;
    UILabel *gStatus;
    UILabel *needEQ;
    UIImageView *sliderB;
    UIImageView *sliderU;
    UILabel *ewokanLabel;
    
    UILabel *syff;
    UILabel *syffContent;
    
    UILabel *nrsm;
    UILabel *nrsmContent;
    
    UILabel *zysx;
    UILabel *zysxContent;
    
    UILabel *xgzy;
    
    UITapGestureRecognizer *tap;
    
}

@property (nonatomic, strong) NSDictionary *detailDic;
@property (strong, nonatomic) IBOutlet UIView *STAlertView;
@property (weak, nonatomic) IBOutlet UIView *contentView;
- (IBAction)hideAlertAction:(UIButton *)sender;

@property (strong, nonatomic) IBOutlet UIView *kaSTalertView;
@property (weak, nonatomic) IBOutlet UIView *kaContentView;
- (IBAction)hideKaAlertAction:(UIButton *)sender;

@end

@implementation GiftDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        UILabel *t = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
        t.font = [UIFont systemFontOfSize:16];
        t.textColor = [UIColor blackColor];
        t.backgroundColor = [UIColor clearColor];
        t.textAlignment = UITextAlignmentCenter;
        t.text = @"礼包放送";
        self.navigationItem.titleView = t;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self loadGiftdata];
    [self loadScrollerView];
}

- (void)loadScrollerView
{
    scrView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 65 - 55)];
    scrView.backgroundColor = [UIColor whiteColor];
    scrView.tag = 10;
    
    
    headImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 80, 80)];
    [scrView addSubview:headImg];
    
    gNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 200, 20)];
    gNameLabel.font = [UIFont systemFontOfSize:16];
    [scrView addSubview:gNameLabel];
    
    
    gTypeLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 35, 100, 15)];
    gTypeLabel.font = [UIFont systemFontOfSize:13];
    gTypeLabel.textColor = [UIColor darkGrayColor];
    [scrView addSubview:gTypeLabel];
    
    gStatus = [[UILabel alloc] initWithFrame:CGRectMake(200, 35, 120, 15)];
    gStatus.font = [UIFont systemFontOfSize:13];
    gStatus.textColor = [UIColor darkGrayColor];
    [scrView addSubview:gStatus];
    
    needEQ = [[UILabel alloc] initWithFrame:CGRectMake(100, 55, 200, 15)];
    needEQ.font = [UIFont systemFontOfSize:13];
    needEQ.textColor = [UIColor darkGrayColor];
    [scrView addSubview:needEQ];
    
    sliderB = [[UIImageView alloc] initWithFrame:CGRectMake(100, 75, 180, 15)];
    [sliderB setImage:[UIImage imageNamed:@"kX2_05.png"]];
    [scrView addSubview:sliderB];
    
    sliderU = [[UIImageView alloc] initWithFrame:CGRectMake(102, 78, 0, 9)];
    UIImage *img = [UIImage imageNamed:@"kX2_09.png"];
    [img stretchableImageWithLeftCapWidth:45 topCapHeight:0];
    [sliderU setImage:img];
    [scrView addSubview:sliderU];
    
    ewokanLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 15)];
    ewokanLabel.left = sliderB.right + 5;
    ewokanLabel.top = sliderB.top;
    ewokanLabel.font = [UIFont systemFontOfSize:13];
    ewokanLabel.textColor = [UIColor darkGrayColor];
    [scrView addSubview:ewokanLabel];
    
    
    syff = [[UILabel alloc] initWithFrame:CGRectMake(headImg.left, headImg.bottom +15, 300, 15)];
    syff.backgroundColor = [UIColor colorWithWhite:0.769 alpha:0.150];
    syff.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
    syff.text = @"使用方法";
    syff.font = [UIFont systemFontOfSize:13];
    syff.textColor = [UIColor blackColor];
    [scrView addSubview:syff];
    
    syffContent = [[UILabel alloc] initWithFrame:CGRectMake(headImg.left, syff.bottom , 300, 0)];
    syffContent.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
    syffContent.numberOfLines = 0;
    syffContent.font = [UIFont systemFontOfSize:13];
    syffContent.textColor = [UIColor darkGrayColor];
    [scrView addSubview:syffContent];
    
    
    nrsm = [[UILabel alloc] initWithFrame:CGRectMake(headImg.left, 0, 300, 15)];
    nrsm.backgroundColor = [UIColor colorWithWhite:0.769 alpha:0.150];
    nrsm.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
    nrsm.text = @"内容说明";
    nrsm.font = [UIFont systemFontOfSize:13];
    nrsm.textColor = [UIColor blackColor];
    [scrView addSubview:nrsm];
    
    nrsmContent = [[UILabel alloc] initWithFrame:CGRectMake(headImg.left, syff.bottom +10, 300, 0)];
    nrsmContent.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
    nrsmContent.numberOfLines = 0;
    nrsmContent.font = [UIFont systemFontOfSize:13];
    nrsmContent.textColor = [UIColor darkGrayColor];
    [scrView addSubview:nrsmContent];
    
    zysx = [[UILabel alloc] initWithFrame:CGRectMake(headImg.left, 0, 300, 15)];
    zysx.backgroundColor = [UIColor colorWithWhite:0.769 alpha:0.150];
    zysx.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
    zysx.text = @"注意事项";
    zysx.font = [UIFont systemFontOfSize:13];
    zysx.textColor = [UIColor blackColor];
    [scrView addSubview:zysx];
    
    zysxContent = [[UILabel alloc] initWithFrame:CGRectMake(headImg.left, syff.bottom +10, 300, 0)];
    zysxContent.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
    zysxContent.numberOfLines = 0;
    zysxContent.font = [UIFont systemFontOfSize:13];
    zysxContent.textColor = [UIColor darkGrayColor];
    [scrView addSubview:zysxContent];
    
    xgzy = [[UILabel alloc] initWithFrame:CGRectMake(headImg.left, 0, 200, 15)];
    xgzy.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
    xgzy.text = @"相关资源";
    xgzy.font = [UIFont systemFontOfSize:13];
    xgzy.textColor = [UIColor blackColor];
    [scrView addSubview:xgzy];
    
    [self.view addSubview:scrView];
}


- (void)setDetailDic:(NSDictionary *)detailDic
{
    _detailDic = detailDic;
    
    [headImg setImageWithURL:[NSURL URLWithString:[detailDic objectForKey:@"litpic"]]];
    gNameLabel.text = [detailDic objectForKey:@"title"];
    gTypeLabel.text = [NSString stringWithFormat:@"类型:%@",[detailDic objectForKey:@"type"]];
    gStatus.text = [NSString stringWithFormat:@"状态:%@",[detailDic objectForKey:@"status"]];
    needEQ.text = [NSString stringWithFormat:@"需要:%@蜗牛蛋",[detailDic objectForKey:@"price"]];
    ewokanLabel.text = [NSString stringWithFormat:@"%@%%",[detailDic objectForKey:@"ka_last"]];
    sliderU.width = 178.0*[[detailDic objectForKey:@"ka_last"] floatValue]/100;
    
    syffContent.top = syff.bottom + 3;
    NSString *syfftextStr = [detailDic objectForKey:@"method"];
    UIFont *font = [UIFont systemFontOfSize:13];
    CGSize size = CGSizeMake(kScreenWidth - 20, 2000);
    CGSize labelsize = [syfftextStr sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByWordWrapping];
    syffContent.text = syfftextStr;
    syffContent.height = labelsize.height;
    
    nrsm.top = syffContent.bottom + 15;
    NSString *nrsmtextStr = [detailDic objectForKey:@"explain"];
    labelsize = [nrsmtextStr sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
    nrsmContent.text = nrsmtextStr;
    nrsmContent.height = labelsize.height;
    nrsmContent.top = nrsm.bottom;
    
    zysx.top = nrsmContent.bottom + 15;
    zysxContent.top = zysx.bottom + 3;
    NSString *zysxtextStr = [detailDic objectForKey:@"remark"];
    labelsize = [zysxtextStr sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
    zysxContent.text = zysxtextStr;
    zysxContent.height = labelsize.height;
    
    
    xgzy.top = zysxContent.bottom +15;

    
    
    int acatNum = [[detailDic objectForKey:@"acat"] intValue];
    int spreeNum = [[detailDic objectForKey:@"spree"] intValue];
    
    NSDictionary *relatedDic = [detailDic objectForKey:@"related"];

    if (acatNum == 0 && spreeNum == 0) {
        xgzy.height = 0;
    }
    
    if (acatNum != 0) {
        NSArray *acatArray = [relatedDic objectForKey:@"acat"];
        
        for (int i = 0; i < acatNum; i++) {
            
            NSDictionary *acatDic = acatArray[i];
            
            GiftButton *giftBtn = [GiftButton buttonWithType:UIButtonTypeCustom];
            
            giftBtn.frame = CGRectMake(10, 0, 0, 0);
            giftBtn.top = xgzy.bottom + 20 + i*42;
            giftBtn.isRedBg = YES;
            giftBtn.hasTao = [[acatDic objectForKey:@"tao"] intValue] == 1 ? YES : NO;
            giftBtn.hasLing = [[acatDic objectForKey:@"lika"] intValue] == 1 ? YES : NO;
            giftBtn.btnTitle = [acatDic objectForKey:@"title"];
            giftBtn.giftId = [acatDic objectForKey:@"id"];
            
            [giftBtn addTarget:self action:@selector(giftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            [scrView addSubview:giftBtn];
        }

    }
    
    if (spreeNum != 0) {
        NSArray *spreeArray = [relatedDic objectForKey:@"spree"];

        for (int i = 0; i < spreeNum; i ++) {
            
            NSDictionary *spreeDic = spreeArray[i];
            
            GiftButton *giftBtn = [GiftButton buttonWithType:UIButtonTypeCustom];
            giftBtn.frame = CGRectMake(10, 0, 0, 0);
            giftBtn.top = xgzy.bottom + 20 + (acatNum+ i)*42;
            giftBtn.isRedBg = NO;
            giftBtn.hasTao = [[spreeDic objectForKey:@"tao"] intValue] == 1 ? YES : NO;
            giftBtn.hasLing = [[spreeDic objectForKey:@"lika"] intValue] == 1 ? YES : NO;
            giftBtn.btnTitle = [spreeDic objectForKey:@"title"];
            giftBtn.giftId = [spreeDic objectForKey:@"id"];
            
            
            [giftBtn addTarget:self action:@selector(giftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            [scrView addSubview:giftBtn];
        }
    }
    
    scrView.contentSize = CGSizeMake(kScreenWidth, zysxContent.bottom + 30 + (acatNum + spreeNum)*80);


}

- (void)giftBtnClick:(UIButton *)btn
{
    GiftDetailViewController *gditailVC = [[GiftDetailViewController alloc] init];
    gditailVC.detailID = [(GiftButton *)btn giftId];
    [self.navigationController pushViewController:gditailVC animated:YES];
}

- (void)loadGiftdata
{
    NSString *url = [NSString stringWithFormat:@"http://m.a.ewoka.com/apply/index/%@",self.detailID];
    __weak GiftDetailViewController *this = self;
    [DataService requestWithURL:url
                         params:nil
                     httpMethod:@"GET"
                    finishBlock:^(id result) {
                        [this loadGiftDataFinished:result];
                    }];
}
- (void)loadGiftDataFinished:(NSDictionary *)result
{
    self.detailDic = result;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**-----------------------------------------------------------------**/

- (IBAction)shareBtnclick:(UIButton *)sender {
    if ([self.STAlertView superview] == nil) {
        [self show];
    }
}

- (IBAction)taokaBtnClick:(UIButton *)sender {
    //http://m.a.ewoka.com/apply/scouring/$1
    NSString *url = [NSString stringWithFormat:@"http://m.a.ewoka.com/apply/scouring/%@",self.detailID];
    __weak GiftDetailViewController *this = self;
    [DataService requestWithURL:url
                         params:nil
                     httpMethod:@"GET"
                    finishBlock:^(id result) {
                        [this loadtaokaFinished:result];
                    }];
}

- (void)loadtaokaFinished:(NSDictionary *)result
{
    if ([[result objectForKey:@"reg"] intValue]!=0) {
        self.stkaImgView.image = [UIImage imageNamed:@"1"];
        self.stkatitleLabel.text = @"领取失败！";
        self.stkatitleLabel.textColor = [UIColor redColor];
        self.stkacontentLabel.text = [result objectForKey:@"msg"];
        self.stkacopyBtn.hidden = YES;
    }else
    {
        self.stkaImgView.image = [UIImage imageNamed:@"XX"];
        self.stkatitleLabel.text = @"领取成功！";
        self.stkatitleLabel.textColor = [UIColor cyanColor];
        self.stkacontentLabel.text = [result objectForKey:@"msg"];
        self.stkacopyBtn.hidden = NO;
        UIPasteboard *appPasteBoard =  [UIPasteboard generalPasteboard];
        appPasteBoard.persistent = YES;
        NSString *pasteStr =self.stkacontentLabel.text;
        [appPasteBoard setString:pasteStr];
    }
    
    if ([self.kaSTalertView superview] == nil) {
        [self kashow];
    }
}



- (IBAction)lingkaBtnClick:(UIButton *)sender {
    
    NSString *url = [NSString stringWithFormat:@"http://m.a.ewoka.com/lika"];
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:[[NSUserDefaults standardUserDefaults] objectForKey:@"appid"],@"appid",self.detailID,@"id", nil];
    __weak GiftDetailViewController *this = self;
    [DataService requestWithURL:url
                         params:dic
                     httpMethod:@"POST"
                    finishBlock:^(id result) {
                        [this loadlingkaFinished:result];
                    }];
}

- (void)loadlingkaFinished:(NSDictionary *)result
{
    if ([[result objectForKey:@"reg"] intValue]!=0) {
        self.stkaImgView.image = [UIImage imageNamed:@"1"];
        self.stkatitleLabel.text = @"领取失败！";
        self.stkatitleLabel.textColor = [UIColor redColor];
        self.stkacontentLabel.text = [result objectForKey:@"msg"];
        self.stkacopyBtn.hidden = YES;
    }else
    {
        self.stkaImgView.image = [UIImage imageNamed:@"XX"];
        self.stkatitleLabel.text = @"领取成功！";
        self.stkatitleLabel.textColor = [UIColor cyanColor];
        self.stkacontentLabel.text = [result objectForKey:@"card"];
        self.stkacopyBtn.hidden = NO;
        UIPasteboard *appPasteBoard =  [UIPasteboard generalPasteboard];
        appPasteBoard.persistent = YES;
        NSString *pasteStr =self.stkacontentLabel.text;
        [appPasteBoard setString:pasteStr];
    }

    
    if ([self.kaSTalertView superview] == nil) {
        [self kashow];
    }
}

//单击复制按钮
- (IBAction)copyBtnClick:(UIButton *)sender {
    UIPasteboard *appPasteBoard =  [UIPasteboard generalPasteboard];
    appPasteBoard.persistent = YES;
    NSString *pasteStr =self.stkacontentLabel.text;
    [appPasteBoard setString:pasteStr];
    
    UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"完成复制",nil),nil] message:pasteStr delegate:nil cancelButtonTitle:NSLocalizedString(@"OK",nil) otherButtonTitles:nil];
    [alertview show];
}

- (IBAction)sinaSharBtnClick:(UIButton *)sender {
    if (NO == [[ShareEngine sharedInstance] isLogin:sinaWeibo])
    {
        [[ShareEngine sharedInstance] loginWithType:sinaWeibo];
    }
    else
    {
        UIActionSheet *sendSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"发送到新浪微博" otherButtonTitles:@"取消授权",nil];
        sendSheet.tag = SINASHEET_TAG;
        [sendSheet showInView:self.view];
    }

}

- (IBAction)tcWeiboSharBtnClick:(UIButton *)sender {
    
    if (NO == [[ShareEngine sharedInstance] isLogin:tcWeibo])
    {
        [[ShareEngine sharedInstance] loginWithType:tcWeibo];
    }
    else
    {
        UIActionSheet *sendSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"发送到腾讯微博" otherButtonTitles:@"取消授权",nil];
        sendSheet.tag = TCSHEET_TAG;
        [sendSheet showInView:self.view];
    }
}

- (IBAction)weixinSharBtnClick:(UIButton *)sender {
    [[ShareEngine sharedInstance] sendWeChatMessage:[NSString stringWithFormat:@"E蜗卡官网,%@,%@",[_detailDic objectForKey:@"title"],SHARE_CONTENT] WithUrl:SHARE_URL WithType:weChat];
}

- (IBAction)pyqSharBtnClick:(UIButton *)sender {
    [[ShareEngine sharedInstance] sendWeChatMessage:[NSString stringWithFormat:@"E蜗卡官网,%@,%@",[_detailDic objectForKey:@"title"],SHARE_CONTENT] WithUrl:SHARE_URL WithType:weChatFriend];
}

- (void)viewWillAppear:(BOOL)animated
{
    [ShareEngine sharedInstance].delegate = self;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [ShareEngine sharedInstance].delegate = nil;
}

- (void)show{
    
    [self.shareHeadImg setImageWithURL:[NSURL URLWithString:[_detailDic objectForKey:@"litpic"]]];
    self.shareLabel.text = [NSString stringWithFormat:@"@E蜗卡官网，%@，%@",[_detailDic objectForKey:@"title"],SHARE_CONTENT];
    
    self.STAlertView.hidden = NO;
    
    tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideAlertAction:)];
    [self.STAlertView addGestureRecognizer:tap];
    self.STAlertView.tag = 91;
    
    
    self.STAlertView.center = CGPointMake(kScreenWidth/2.0, kScreenHeight/2.0);
    [self.view addSubview:self.STAlertView];
    CAKeyframeAnimation *popAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    popAnimation.duration = 0.4;
    popAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.01f, 0.01f, 1.0f)],
                            [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.0f)],
                            [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9f, 0.9f, 1.0f)],
                            [NSValue valueWithCATransform3D:CATransform3DIdentity]];
    popAnimation.keyTimes = @[@0.2f, @0.5f, @0.75f, @1.0f];
    popAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                     [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                     [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [self.STAlertView.layer addAnimation:popAnimation forKey:nil];

}

/**
 *  显示领卡
 */
- (void)kashow
{
    self.kaSTalertView.hidden = NO;
    
    tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKaAlertAction:)];
    [self.kaSTalertView addGestureRecognizer:tap];
    self.kaSTalertView.tag = 81;

    
    
    self.kaSTalertView.center = CGPointMake(kScreenWidth/2.0, kScreenHeight/2.0);
    [self.view addSubview:self.kaSTalertView];
    CAKeyframeAnimation *popAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    popAnimation.duration = 0.4;
    popAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.01f, 0.01f, 1.0f)],
                            [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.0f)],
                            [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9f, 0.9f, 1.0f)],
                            [NSValue valueWithCATransform3D:CATransform3DIdentity]];
    popAnimation.keyTimes = @[@0.2f, @0.5f, @0.75f, @1.0f];
    popAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                     [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                     [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [self.kaSTalertView.layer addAnimation:popAnimation forKey:nil];

}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
    if (self.STAlertView.tag == 91) {
        self.STAlertView.tag = 90;
        [self.STAlertView removeFromSuperview];
    }
    if (self.kaSTalertView.tag == 81) {
        self.kaSTalertView.tag = 80;
        [self.kaSTalertView removeFromSuperview];
    }
}

- (IBAction)hideKaAlertAction:(UIButton *)sender {
    [self.kaSTalertView removeGestureRecognizer:tap];
    CAKeyframeAnimation *hideAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    hideAnimation.duration = 0.4;
    hideAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.0f)],
                             [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0f, 1.0f, 1.0f)],
                             [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.00f, 0.00f, 0.00f)]];
    hideAnimation.keyTimes = @[@0.2f, @0.5f, @0.75f];
    hideAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                      [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                      [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    hideAnimation.delegate = self;
    [self.kaSTalertView.layer addAnimation:hideAnimation forKey:nil];
    
    [self performSelector:@selector(kahideDelay) withObject:nil afterDelay:0.3];
}

- (void)kahideDelay
{
    self.kaSTalertView.hidden = YES;

}

- (IBAction)hideAlertAction:(UIButton *)sender {
    
    [self.STAlertView removeGestureRecognizer:tap];
    CAKeyframeAnimation *hideAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    hideAnimation.duration = 0.4;
    hideAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.0f)],
                             [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0f, 1.0f, 1.0f)],
                             [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.00f, 0.00f, 0.00f)]];
    hideAnimation.keyTimes = @[@0.2f, @0.5f, @0.75f];
    hideAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                      [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                      [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    hideAnimation.delegate = self;
    [self.STAlertView.layer addAnimation:hideAnimation forKey:nil];
    
    [self performSelector:@selector(hideDelay) withObject:nil afterDelay:0.3];

}

- (void)hideDelay
{
    self.STAlertView.hidden = YES;

}

#pragma mark - shareEngineDelegate
- (void)shareEngineSendSuccess
{
    UIAlertView *shareAlert = [[UIAlertView alloc] initWithTitle:@"发送成功" message:@"您的内容已成功分享,谢谢！" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [shareAlert show];
}

- (void)shareEngineSendFail:(NSError *)error
{
    NSString *failDescription = @"请重试！";
    if (20019 == error.code)
    {
        failDescription = @"重复发送了相同的内容！";
    }
    UIAlertView *shareAlert = [[UIAlertView alloc] initWithTitle:@"发送失败" message:failDescription delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [shareAlert show];
}


#pragma mark - aciontSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (SINASHEET_TAG == actionSheet.tag)
    {
        if (0 == buttonIndex)
        {
            [[ShareEngine sharedInstance] sendShareMessage:[NSString stringWithFormat:@"@E蜗卡官网 ，%@，%@",[_detailDic objectForKey:@"title"],SHARE_CONTENT] WithType:sinaWeibo];
        }
        else if (1 == buttonIndex)
        {
            [[ShareEngine sharedInstance] logOutWithType:sinaWeibo];
        }
    }
    else if (TCSHEET_TAG == actionSheet.tag)
    {
        if (0 == buttonIndex)
        {
            [[ShareEngine sharedInstance] sendShareMessage:[NSString stringWithFormat:@"@ewokawl ，%@，%@",[_detailDic objectForKey:@"title"],SHARE_CONTENT] WithType:tcWeibo];
        }
        else if (1 == buttonIndex)
        {
            [[ShareEngine sharedInstance] logOutWithType:tcWeibo];
        }
    }
}




@end
